package com.zdp.seckill.controller;

import com.zdp.seckill.common.domain.ResultInfo;
import com.zdp.seckill.common.utils.ResultInfoUtil;
import com.zdp.seckill.pojo.vo.OrderModel;
import com.zdp.seckill.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author sesshomaru
 * @date 2021/6/19 20:47
 */
@RestController
@RequestMapping("/order")
public class OrderController extends BaseController{

    @Autowired
    private OrderService orderService;

    @Resource
    private HttpServletRequest httpServletRequest;

    //封装下单请求
    @RequestMapping(value = "/createorder",method = {RequestMethod.POST},consumes={CONTENT_TYPE_FORMED})
    @ResponseBody
    public ResultInfo createOrder(@RequestParam(name="itemId")Integer itemId,
                                  @RequestParam(name="amount")Integer amount,
                                  @RequestParam(name = "promoId", required = false)Integer promoId) {
        //TODO 验证用户登录状态

        Integer userId = 31;
        OrderModel orderModel = orderService.createOrder(userId, itemId, promoId, amount);
        return ResultInfoUtil.buildSuccess(httpServletRequest.getRequestURI());
    }
}
